package com.share.common.utils;

import org.icepear.echarts.Bar;
import org.icepear.echarts.render.Engine;

import java.util.HashMap;
import java.util.Map;

public class EChartsUtil {
    private static Engine engine = new Engine();

    //测试一个bar图像
    public static String bar() {
        Bar bar = new Bar();
        bar.setLegend().setTooltip("item")
                .addXAxis(new String[]{"a1", "a2", "a3", "a4"})
                .addYAxis()
                .addSeries("2015", new Number[]{12, 42, 13, 13})
                .addSeries("2016", new Number[]{12, 42, 13, 13})
                .addSeries("2017", new Number[]{12, 42, 13, 13});
        return engine.renderJsonOption(bar);
    }

    public static void main(String[] args) throws Exception {
//        String url = "http://127.0.0.1:8602/genEchartsImage";
//        String bar = bar();
//        try {
//            byte[] bytes = HttpUtil.downFile(url, bar);
//            FileUtil.writeByte("D:\\open-project\\we-share\\a.png", bytes);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }


//        File file = new File("D:\\data\\3.png");
//        String url = "http://127.0.0.1:9032/base64";
//        byte[] bytes = FileUtil.readByte(file);
//        String s = Base64.getEncoder().encodeToString(bytes);
//        JSONObject obj = new JSONObject();
//        obj.put("image", s);
//
//        String post = HttpUtil.post(url, obj.toJSONString(),null,300000);
//        System.out.println(post);

        String url = "http://127.0.0.1:9032/imageUrl";
        Map<String, Object> obj = new HashMap<>();
        obj.put("imageUrl", "https://p3.itc.cn/q_70/images03/20211117/1270baf1c2f84fa19a99ef82c52d454c.png");
//        obj.put("imageUrl", "11cpng");
        String post = HttpUtil.get(url, obj, 30000);
        System.out.println(post);
    }
}
